//
//  QSVisitInterFace.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/4/2.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSVisitInterFace.h"
#import "QSRequestManager.h"
@implementation QSVisitInterFace
/**
* @brief 获取走访头部展示信息
*/
+ (void)getApiVisitDetail:(void (^)(ResponseMessage *rspStatusAndMessage, QSVisitHeaderInfoModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kApiVisitDetails];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSVisitHeaderInfoModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            model = [QSVisitHeaderInfoModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}


/**
* @brief 获取走访记录List
 *level 前方法得到的级别
 *epId 组长——如果切换了组员
 *egId 领导——如果切换了组
 *startTime 开始时间 -时间戳
 *endTime 结束时间
 *companyKey 服务员——如果切换了公司
*/
+ (void)getVisitListWithPageIndex:(NSInteger)pageIndex
                              Level:(NSInteger)level
                            Epid:(NSInteger)epId
                            Egid:(NSInteger)egId
                      CompanyName:(NSString *)companyName
                        StartTime:(NSString *)startTime
                          EndTime:(NSString *)endTime
                         AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSVisitHomeListModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kEnterpriseVisitList];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    if (epId) {
        [bodyDic setObject:@(epId) forKey:@"epId"];
    }
    if (egId) {
        [bodyDic setObject:@(egId) forKey:@"egId"];
    }
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setValue:@(10) forKey:@"pageSize"];
    [bodyDic setObject:@(level) forKey:@"level"];
    [bodyDic setObject:QSNoNilString(startTime) forKey:@"startTime"];
    [bodyDic setObject:QSNoNilString(endTime) forKey:@"endTime"];
    [bodyDic setObject:QSNoNilString(companyName) forKey:@"companyName"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        QSVisitHomeListModel *model;
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            model = [QSVisitHomeListModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

/**
* @brief 获取走访记录List
 *evCompanyKey 企业ID
 *evType 走访类型
 *evTime 走访时间
 *evFollow 跟进联系人
 *evRemark 备注
 *evPic 图片或视频url
 *evSignId 签到ID
 *problemList 问题列表
*/
+ (void)postAddNewVisitWithEvCompanyKey:(NSString *)evCompanyKey
                              EvType:(NSString *)evType
                            EvTime:(NSString *)evTime
                            EvFollow:(NSString *)evFollow
                      EvRemark:(NSString *)evRemark
                        EvPic:(NSString *)evPic
                          EvSignId:(NSString *)evSignId
                            ProblemList:(NSArray *)problemList
                               AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kVisitInsert];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    if (evSignId) {
        [bodyDic setObject:evSignId forKey:@"evSignId"];
    }
    if (evPic) {
        [bodyDic setObject:evPic forKey:@"evPic"];
    }
    if (evRemark) {
        [bodyDic setObject:evRemark forKey:@"evRemark"];
    }
    if (problemList.count) {
        [bodyDic setObject:problemList forKey:@"problemList"];
    }
    [bodyDic setObject:QSNoNilString(evCompanyKey) forKey:@"evCompanyKey"];
    [bodyDic setObject:QSNoNilString(evType) forKey:@"evType"];
    [bodyDic setObject:QSNoNilString(evTime) forKey:@"evTime"];
    [bodyDic setObject:QSNoNilString(evFollow) forKey:@"evFollow"];
    
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
* @brief 获取走访记录表里的问题数据
 *eviD 前方法得到的问题id
*/
- (void)getVisitProblemListWithEvId:(NSString *)evid
                           AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSArray *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetProblemListByEvId];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:evid forKey:@"evId"];
    
    [QSRequestManager executeTokenReturnArrayGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSArray *responseArr) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dic in responseArr) {
                QSVisitProblemModel *model = [QSVisitProblemModel mj_objectWithKeyValues:dic];
                [arr addObject:model];
            }
            block(rspStatusAndMessage, arr.copy);
        }
    }];
}

/**
* @brief 根据切换小组成员/小组切换企业筛查条件
 *epId 小组取组员的id
 *egId领导取小组的id
*/
+ (void)getVisitCompanysWithEpId:(NSString *)epId
                            EgId:(NSString *)egId
                        AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSArray *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kApiVisitCompanys];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    if (epId) {
        [bodyDic setObject:epId forKey:@"epId"];
    }
    if (egId) {
        [bodyDic setObject:egId forKey:@"egId"];
    }
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode && responseDataDic) {
            NSMutableArray *array = [NSMutableArray array];
            for (NSDictionary *dic in responseDataDic[@"list"]) {
                QSVisitInfoCompanyListModel *model = [QSVisitInfoCompanyListModel mj_objectWithKeyValues:dic];
                [array addObject:model];
            }
            block(rspStatusAndMessage, array.copy);
        }
    }];
}


/**
 * @brief 获取公司列表 （模糊搜索）
 *CompanyName 公司名称
 *epAllCompany  是否展示全部企业
*/
+ (void)getApiSearchCompanyWithPageIndex:(NSInteger )pageIndex
                            EpAllCompany:(NSString* )epAllCompany
                            CompanyName:(NSString *)companyName
                               andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSBindingEnterprisesModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kSearchCompany];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [bodyDic setObject:epAllCompany forKey:@"epAllCompany"];

    if (companyName) {
        [bodyDic setObject:companyName forKey:@"companyName"];
    }
    
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            QSBindingEnterprisesModel *model = [QSBindingEnterprisesModel mj_objectWithKeyValues:responseDic];
            block(rspStatusAndMessage, model);
        }
    }];
}
/**
 * @brief Visit 返回头部item
 */
+ (void)getVisitHeaderItemAndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSUserHomeItemModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetVisitItem];
     NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode  && responseDataDic) {
            QSUserHomeItemModel *model = [QSUserHomeItemModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

@end
